<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
<link rel="shortcut icon" href="img/ic.png">
    <title>赛场详情</title>

    <!-- Bootstrap Core CSS -->
    <link href="css/bootstrap.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="css/sb-admin.css" rel="stylesheet">
<link href="dist/css/bootstrapValidator.css" rel="stylesheet">
    <!-- Morris Charts CSS -->
    <link href="css/plugins/morris.css" rel="stylesheet">

    <!-- Custom Fonts -->
    <link href="font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
    <link href="nuget/content/content/toastr.css" rel="stylesheet" type="text/css"/>
	<!-- tab table-->
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
	<script src="js/cdn/html5shiv-3.7.0.js"></script>
	<script src="js/cdn/respond-1.4.2.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" href="css/cdn/dataTables.bootstrap.css">
	<link rel="stylesheet" href="css/cdn/font_i0327076nave7b9.css">
    <link rel="stylesheet" type="text/css" href="css/datatable.css"/>
    <style>
		#example_paginate{
			float:right;
		}
		.handle-btn{
			cursor: pointer;
		    margin: 0 2px;
		}
		#wrapper {
		    padding-left:0px;
		}
		.navigation{
			border-bottom: 3px solid #edebeb;
		}
		.navigation a:hover{
			color: #0F6AFC;
			border-bottom: 2px solid #01AAED;
		}
		.this{
			color: #01aaed;
			font-weight:bold;
			border-bottom: 2px solid #01AAED;
		}
		[v-cloak] {
			display: none;
		}
		tbody tr{
			line-height: 28px;
		}
	</style>
</head>

<body>

    <div id="wrapper">
        <div id="page-wrapper">
            <div class="container-fluid">
				<div class="row sss">
					<nav class="navbar navbar-default" role="navigation">
						<div>
							<ul class="nav navbar-nav">
								<li><a href="index.html">首页</a></li>
								<li><a href="Court.html">赛场维护</a></li>
								<li class="active"><a href="javascript:;"><span class="xuanzhong">赛场详情</span></a></li>
							</ul>
						</div>
					</nav>
				</div>
                <!-- /.row -->
                 <div class="row">
                	<div class="panel ">
                        <div class="panel-heading">
                        	<ul class="nav">
                        		<li style="float: left;">
                        			<h3 class="panel-title" style="line-height: 34px;" v-cloak>{{dataObj.stadiumName}}<span style="margin: 0 10px;"> 创建时间 </span>{{dataObj.createTime | timeChange(0)}}</h3>
                        		</li>
                        	</ul>
                        </div>
                        	<ul class="nav">
                        		<li style="float: left; padding-left: 24%; line-height: 34px; font-size: 16px; color: #1aa79d;"><b>场景库</b></li>
                        		<li style="float: right;">
                        			<button type="button" v-on:click="qing()"  class="btn btn-default">清空场景</button>
                        		</li>
                        		<li style="float: right;">
                        			<div class="btn-group" style="float: right; margin-right: 30px;">
										<button type="button" v-on:click="modify()" class="btn btn-primary">保存场景</button>
									</div>
                        		</li>
                        	</ul>
	                        <div class="panel-body">
	                            <div class="panel-body">
			                       <div class="selectbox" id="select3">
										
										<!--style="overflow-x: auto; overflow-y: auto; height: 280px;"-->
										<div class="col-sm-6" >
											<table align="center" border="1" class="col-sm-12" v-cloak id="select1" style="border: #C0C0C0;">
												<thead>
											        <tr style="background: #1aa79d; background-color: #1aa79d; color: #fff; line-height: 30px; ">
											        	<td align="center" style="width: 120px;">序号</td>
											            <td align="center">路段场景名称</td>
											            <td align="center" style="width: 120px;">添加</td>
											        </tr>
										        </thead>
										        <tbody>
											        <tr v-for="(item,index) in roadScenesList">
													    <td align="center">{{index+1}}</td>
													    <td align="center">{{item.scenesName}}</td>
													    <td class="roadadd" align="center"><span class="glyphicon glyphicon-plus-sign jia"></span></td>
													</tr>
												</tbody>
											    <table align="center" border="1" class="col-sm-12" style="margin-top:10px;border: #C0C0C0;" id="select2" v-cloak >
											    	<thead>
											        <tr style="background: #1aa79d; background-color: #1aa79d; color: #fff; line-height: 30px; ">
											        	<td align="center" style="width: 120px;">序号</td>
											            <td align="center">普通场景名称</td>
											            <td align="center" style="width: 120px;">添加</td>
											        </tr>
											        </thead>
											        <tbody>
												        <tr v-for="(item,index) in normalScenesList">
												        	<td align="center">{{index+1}}</td>
												            <td align="center">{{item.scenesName}}</td>
												            <td class="normaadd" align="center"><span class="glyphicon glyphicon-plus-sign jia"></span></td>
												        </tr>
											        </tbody>
											    </table>
										   </table>
										</div>
										<div class="col-sm-6" >
											<table align="center" border="1" class="col-sm-12" style="border: #C0C0C0;" v-cloak>
												<thead>
											  		<tr style="background: #1aa79d; background-color: #1aa79d; color: #fff; line-height: 30px; ">
											  			<td align="center">移除</td>
											  			<td align="center">序号</td>
											            <td align="center">场景名称</td>
											            <td align="center">类型</td>
											        </tr>
										       </thead>
										       <tbody id="tuo">
											        <tr class="ter" v-for="(item,index) in resultScenesList">
											        	<td v-on:click="cont(index)" align="center"><span class="glyphicon glyphicon-minus-sign jian"></span></td>
											        	<td align="center">{{index+1}}</td>
											            <td align="center">{{item.scenesName}}</td>
											            <td align="center">{{item.scenesType === 0?"普通":"路段"}}</td>
											            <input id="scenesId" name="scenesId" type="hidden" :value="item.scenesId"/>
												    </tr>
											    </tbody>
										    </table>
										</div>
									</div>
			                    </div>
	                        </div>
                   </div>
                </div>
                <!-- /.row -->
            </div>
            <!-- /.container-fluid -->

        </div>
        <!-- /#page-wrapper -->
	
    </div>
    <!-- /#wrapper -->

    <!-- jQuery -->
    <script src="js/jquery.js"></script>

    <!-- Bootstrap Core JavaScript -->
    <script src="js/bootstrap.min.js"></script>
	<!-- tab table-->
	<script src="js/cdn/jquery.dataTables.min.js"></script>
	<script src="js/cdn/dataTables.bootstrap.js"></script>
	<!-- device-->
	<script src="nuget/content/scripts/toastr.js"></script>
	<script type="text/javascript" src="dist/js/bootstrapValidator.min.js"></script>
	<script type="text/javascript" src="js/common.js" ></script>
	<script type="text/javascript" src="js/vue/vue.js" ></script>
	<script type="text/javascript" src="js/vue/vue-router.js" ></script>
	<script type="text/javascript" src="js/jquery.dragsort-0.5.2.min.js" ></script>
	<script>
        var userName = localStorage.getItem("userName");    $("#userName").text(userName);
		Vue.filter("timeChange", function(value) {
			return replaceTime(value / 1000);
		});
		var vue = new Vue({
		  el: '#wrapper',
		  data:{
		  	detailsUrl:"Exhibition.html?stadiumId="+stadiumId,
		  	dataObj: {
		  		teamOrganization:'',
		  		teamLeader:'',
		  		stadiumName:''
		  	},
		  	roadScenesList:[],
		  	normalScenesList:[],
		  	resultScenesList:[]//左侧
		  },
		  mounted:function(){
		  	this.addTable();
		  	this.deviceBasicId();
		  	this.Initialization();
		  	this.result();
		  },
		  methods:{
		  	//初始化显示详情
		  	deviceBasicId:function(){
		  		var _self = this;
		  		$(document).ready(function() {
				  var myTable = $('#example').DataTable({
				      "processing": false, //DataTables载入数据时，是否显示‘进度’提示
				      "stateSave": true, //是否打开客户端状态记录功能,此功能在ajax刷新纪录的时候不会将个性化设定回复为初始化状态
				      "scrollCollapse": true, //是否开启DataTables的高度自适应，当数据条数不够分页数据条数的时候，插件高度是否随数据条数而改变
				      "paginationType": "full_numbers", //详细分页组，可以支持直接跳转到某页
				      "language": lang, //提示信息
				      "destroy":true,//Cannot reinitialise DataTable,解决重新加载表格内容问题
				      "autoWidth": true, //自适应宽度，
				      "lengthMenu": [8, 30, 50],
				      "stripeClasses": ["odd", "even"], //为奇偶行加上样式，兼容不支持CSS伪类的场合
				      "showRowNumber":true,
				      "searching": false, //是否允许Datatables开启本地搜索
				      "paging": false, //是否开启本地分页
				      "lengthChange": false, //是否允许产品改变表格每页显示的记录数
				      "info": false, //控制是否显示表格左下角的信息
				      //跟数组下标一样，第一列从0开始，这里表格初始化时，第四列默认降序
				      "order": [0, 'asc'], //asc升序   desc降序
				      "aoColumnDefs": [{
				        "orderable": false,
				        "aTargets": [1,2,3,4] // 指定列不参与排序
				      }],
				      "deferRender": true, //延迟渲染
				      //"ajax":"json/device.json",
				      "ajax": {
				      	url : url +'/users/'+adminId+'/stadiums/'+stadiumId,
						type : 'get',
						data:{
							"currentPage":1,
							"pageSize":9999,
						},
						dataType : 'json',
						beforeSend: function(request) {
				            request.setRequestHeader("accessToken", accessToken);
				        },
						success : function(data) {
							if(data['code'] == 1){
								if(data.result.scenesInfoList.length != 0)
									$('#example').dataTable().fnAddData(data.result.scenesInfoList);
								else
									$('#example').dataTable().fnClearTable();
							}
						}
				      }, //数据的路径 "http://192.168.5.133:8081/ic-iot/admin/'+adminId+'/devices" /"json/device.json"

				      "columns": [{ //定义列
				        "data":"riwso",
				        "render":function(data, type, full, meta ){
				        	return (meta.row+1);
				        },
				        "width":"50px",
				        "sTitle": "序号", //标题
				        "sDefaultContent": "", //此列默认值为""，以防数据中没有此值，DataTables加载数据的时候报错
				      }, {
				      	"data": function(obj){
				            return '<a href="sceneDetails.html?scenesId=' + obj.scenesId + '" target="_blank">' + obj.scenesName + '</a>';

				        },
				      	"sTitle":"场景名称",
				      	"sDefaultContent": "",
				      },{
				      	"data": function(obj){

				            if(obj.scenesType == '0'){
				            	return '场景';
				            }else if(obj.scenesType == '1'){
				            	return '路段';
				            }else{
				            	return '';
				            }

				        },
				      	"sTitle":"类型",
				      	"sDefaultContent": "",
				      },{
				      	"data": function(obj){
				            return obj.scenesScore+'分';
				        },
				      	"sTitle":"总分值",
				      	"sDefaultContent": "",
				      },{
				      	"data": function(obj){
				            return obj.illegalCount+'项';
				        },
				      	"sTitle":"违规项",
				      	"sDefaultContent": "",
				      }],
				    });
				});
		  	},
		  	//编辑
		  	RefereeModal:function(){
		  		var datas = formToJson($("#addform"));
		  		var th = this;
		  		$.ajax({
		  			type: "PUT",
		  			url:url+'/users/'+adminId+'/stadiums/'+stadiumId,
		  			data:datas,
		  			async: false,
		  			dataType: 'json',
					contentType: "application/json; charset=utf-8",
		  			beforeSend: function(request) {
						request.setRequestHeader("accessToken", accessToken);
					},
					success: function(data) {
						if(data.code == 1){
							$('#RefereeModal').modal('hide');
							location.reload();
						}else{
							toastr['error'](data.description);
						}
						
					}
		  		});
		  	},
		  	//初始化
		  	Initialization:function(){
		  		var _self=this;
		  		$.ajax({
		  			type: "get",
		  			url:  url +'/users/'+adminId+'/stadiums/'+stadiumId,
		  			async: false,
		  			dataType: 'json',
					contentType: "application/json; charset=utf-8",
		  			beforeSend: function(request) {
						request.setRequestHeader("accessToken", accessToken);
					},
					success: function(data) {
						if(data.code == 1){
							_self.dataObj = {};
							var result = data.result;
							_self.dataObj = result;
						}else{
							toastr['error'](data.description);
						}
						
					}
		  		});
		  	},
		  	addTable:function(){
		  		var _self=this;
		  		$.ajax({
		  			type: "get",
		  			url:  url +'/users/'+adminId+'/scenes/all',
		  			async: false,
		  			dataType: 'json',
					contentType: "application/json; charset=utf-8",
		  			beforeSend: function(request) {
						request.setRequestHeader("accessToken", accessToken);
					},
					success: function(data) {
						if(data.code == 1){
							var result = data.result;
							var scenesList = result;
							for(var i=0;i<scenesList.length;i++){
								if(scenesList[i].scenesType==0)
									_self.normalScenesList.push(scenesList[i]);
								else if(scenesList[i].scenesType==1)
									_self.roadScenesList.push(scenesList[i]);
							}
						}else{
							toastr['error'](data.description);
						}
						
					}
		  		});
		  	},
		  	//左边列表
		  	result:function(){
		  		var _self=this;
		  		$.ajax({
		  			type: "get",
		  			url:  url +'/users/'+adminId+'/stadium/'+stadiumId+'/stadiumScenes',//resultScenesList
		  			async: false,
		  			dataType: 'json',
		  			beforeSend: function(request) {
						request.setRequestHeader("accessToken", accessToken);
					},
					success: function(data) {
						if(data.code == 1){
							var result = data.result;
							_self.resultScenesList = result;
						}else{
							toastr['error'](data.description);
						}
						
					}
		  		});
		  	},
		  	//保存
		  	modify:function(){
		  		scenesIds = "";
		  		for(var i=0; i<vue.resultScenesList.length;i++){
		  			if(i==0){
					 	scenesIds = vue.resultScenesList[i].scenesId;
					}else{
					 	scenesIds = scenesIds +','+ vue.resultScenesList[i].scenesId;
					}
		  		}
		  		debugger;
		  		if(scenesIds == ""){
		  			toastr['error']('至少选择一条场景');
		  		}else{
		  			var th = this;
			  		$.ajax({
			  			type : "post",
			  			url : url+'/stadium/'+stadiumId+'/scenes',
			  			data :{
			  				"scenesIds":scenesIds,
			  			},
			  			async: false,
			  			dataType: 'json',
			  			beforeSend: function(request) {
							request.setRequestHeader("accessToken", accessToken);
						},
						success: function(data) {
							if(data['code'] == 1){
								toastr['success'](data.description);
								setTimeout(function(){window.close()},3000);
							}else{
								toastr['error'](data.description);
							}
							//th.deviceBasicId();//刷新
						}
			  		});
		  		}
		  		
		  	},
		 	cont:function(index){
		 		vue.resultScenesList.splice(index,1);
//		 		console.log(vue.resultScenesList)
		 	},
		 	qing:function(){
		 		vue.resultScenesList=[];
		 	}
		 	
		  },
		});
		
		$(function(){
			/*$("#tuo").dragsort({
		        itemSelector: "tr",
		        dragSelector: "tr",
		        dragBetween: true,
		        placeHolderTemplate: "<tr></tr>",
		        dragEnd:function(){
		        	debugger
		        	console.log(this);
		        }
		    });*/
			//选择
			$("#select2 .normaadd").click(function(){
				//$(this).clone(true).appendTo('#select3');
				//var order=$(this).context.rowIndex;
				var order=$(this).parent().index();
				
				/*for(var j=0;j<vue.resultScenesList.length;j++){
					if(vue.resultScenesList[j].scenesId == vue.normalScenesList[order].scenesId)
					return toastr['error']('请勿重复添加'); 
				}*/
				vue.resultScenesList.push(vue.normalScenesList[order]);
			});
			$("#select1 .roadadd").click(function(){
				var order=$(this).parent().index();
				
				vue.resultScenesList.push(vue.roadScenesList[order]);
			});

		})
	</script>
</body>

</html>
